package com.zyong.design.pattern.memento.case3;

/**
 * @program: zyong-design-pattern
 * @ClassName: Client
 * @author: zyong
 * @create: 2024-05-12 23:40
 */
public class Client {
    public static void main(String[] args) {
        Original original = new Original();
        Caretaker caretaker = new Caretaker();

        recordResults(original, caretaker);

        Memento memento1 = caretaker.get(1);
        original.getOriginalFromMemento(memento1);
        System.out.println("恢复第一名的成绩信息:" + original);

        Memento memento3 = caretaker.get(3);
        original.getOriginalFromMemento(memento3);
        System.out.println("恢复第三名的成绩信息:" + original);

        // 清空记录下一组
        caretaker.remove();
    }

    private static void recordResults(Original original, Caretaker caretaker) {
        original.setName("张三");
        original.setTimestamp(2330);

        Memento memento1 = original.createMemento();
        caretaker.add(memento1);

        original.setName("李四");
        original.setTimestamp(2550);

        Memento memento2 = original.createMemento();
        caretaker.add(memento2);

        original.setName("王五");
        original.setTimestamp(2560);

        Memento memento3 = original.createMemento();
        caretaker.add(memento3);
    }
}
